<style>
    .warehourse-pa-page{}
    .warehourse-pa-page .el-dialog--large{width:70%;}

    
    .warehourse-pa-page p{display:inline-block;}
    
    .warehourse-pa-page .my-transfer-box{}
    .warehourse-pa-page .my-transfer-box .left-box{width:42%;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title{width:100%;margin-bottom:10px;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title h2{width:100%;line-height:30px;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title .left-title-content{position:relative;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title .left-title-content .lineBlock{position: absolute;right: 0;bottom: 34px;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title .left-title-content .lineBlock.bottom1{bottom: 3px;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title .el-radio-group{padding-left:15px;width:30%;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title .el-radio-group .el-radio{margin-bottom:6px;display:block;}
    .warehourse-pa-page .my-transfer-box .left-box .left-title .el-radio+.el-radio{margin-left:0;}
    .warehourse-pa-page .my-transfer-box .right-box{width:42%;}
    .warehourse-pa-page .my-transfer-box .right-box .right-title{width:100%;}
    .warehourse-pa-page .my-transfer-box .right-box .right-title h2{width:100%;line-height:30px;}

    .warehourse-pa-page .my-transfer-box .transfer-content{padding:5%;width:90%;border:1px solid #ccc;overflow-x:hidden;overflow-y:scroll;}
    .warehourse-pa-page .my-transfer-box .transfer-content .el-checkbox-group label{display:block;margin:0 0 10px 0;}

    .warehourse-pa-page .my-transfer-box .left-transfer{height:340px;}

    .warehourse-pa-page .my-transfer-box .center-transfer{width:16%;margin:180px auto 0;}
    .warehourse-pa-page .my-transfer-box .center-transfer .el-button{width:48px;display:block;margin:0 auto 10px!important;}

    .warehourse-pa-page .my-transfer-box .right-transfer{height:253px;}
</style>
<template>
    <div class="warehourse-pa-page">
        <el-form :inline="true" :model="whPAuthorityForm" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <el-form-item label="登录账号" class="selectMB10 label-w1">
                <el-input size="mini" v-model="whPAuthorityForm.userAccount" placeholder="请输入登录账号"></el-input>
            </el-form-item>
            <el-form-item label="人员名称" class="selectMB10 label-w1">
                <el-input size="mini" v-model="whPAuthorityForm.userName" placeholder="请输入人员名称"></el-input>
            </el-form-item>
            <el-form-item label="供应商名称" class="selectMB10 label-w2">
                <el-input size="mini" v-model="whPAuthorityForm.partnerName" placeholder="请输入供应商名称"></el-input>
            </el-form-item>
            <el-form-item label="库区编码" class="selectMB10 label-w1">
                <el-input size="mini" v-model="whPAuthorityForm.storageSectionCode" placeholder="请输入库区编码"></el-input>
            </el-form-item>
            <el-form-item label="库区名称" class="selectMB10 label-w1">
                <el-input size="mini" v-model="whPAuthorityForm.storageSectionName" placeholder="请输入库区名称"></el-input>
            </el-form-item>
            <el-form-item label="法人名称" class="selectMB10 label-w1">
                <el-input size="mini" v-model="whPAuthorityForm.legalPersonName" placeholder="请输入法人名称"></el-input>
            </el-form-item>
            <el-form-item label="库房编码" class="selectMB10 label-w1">
                <el-input size="mini" v-model="whPAuthorityForm.warehouseCode" placeholder="请输入库房编码"></el-input>
            </el-form-item>
            <el-form-item label="库房名称" class="selectMB10 label-w1">
                <el-input size="mini" v-model="whPAuthorityForm.warehouseName" placeholder="请输入库房名称"></el-input>
            </el-form-item>
             <el-form-item label="当前状态" class="selectMB10 label-w1" style="margin-right: 10px;">
                <el-select size="mini" clearable v-model="whPAuthorityForm.status" placeholder="请选择">
                    <el-option v-for="(status,index) in statusLists" :key="index" :label="status.label" :value="status.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item class="selectMB10">
                <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryWhPAuthority()">查询</el-button>
            </el-form-item>
        </el-form>
        <!--表格-->
        <label class="default-label">库房人员列表：</label>
        <!--新增按钮-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="createNew()">新增</el-button>
        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="importFile">导入</el-button>
        <el-table :data="whPAuthorityData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
            <el-table-column label="操作" header-align="center" align="center" width="60">
                <template scope="scope">
                    <div class="operationItem bolder" v-if="scope.row.status" @click="handleStatus(scope.$index,scope.row)">禁用</div>
                    <div class="operationItem bolder" v-else @click="handleStatus(scope.$index,scope.row)">启用</div> 
                    <!-- 
                    <div class="operationItem disabled bolder" v-if="scope.row.status">修改</div>
                    <div class="operationItem bolder" v-else @click="handleUpdate(scope.$index,scope.row)">修改</div>
                    -->
                </template>
            </el-table-column>
            <el-table-column prop="userAccount" label="登录账号" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column prop="userName" label="人员名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="statusName" label="状态" header-align="center" align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="storageSectionCode" label="库区编码" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column prop="storageSectionName" label="库区名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="warehouseCode" label="库房编码" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column prop="warehouseName" label="库房名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="legalPersonName" label="法人名称" header-align="center" show-overflow-tooltip></el-table-column>
        </el-table>
        <!--分页-->
        <el-pagination v-if="isPaging" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageIndex"  :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>
         <!--新建弹窗-->
        <el-dialog title="新增库房人员权限" :visible.sync="dialogForm1Visible" size="large" :lock-scroll="false">
            <p class="condition">法人名称：</p>
            <el-select size="mini" clearable v-model="legalPersonId"  @change="selectedLegalPersonList" placeholder="请选择">
                <el-option v-for="(LegalPersonData,index) in legalPersonLists" :key="index" :label="LegalPersonData.legalPersonName" :value="LegalPersonData.id">
                    <span style="float: left">{{ LegalPersonData.legalPersonName }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px">{{ LegalPersonData.legalPersonCode }}</span>
                </el-option>
            </el-select>
            <!-- 法人列表 -->
            <div class="my-transfer-box clearfix">
                <div class="left-box fleft">
                    <div class="left-title">
                        <h2>可选人员列表</h2>
                        <div class="left-title-content">
                            <el-radio-group v-model="personnelSources" @change="handlePersonnelSources">
                                <el-radio :label="3">本部人员</el-radio>
                                <el-radio :label="6">业务合作人员</el-radio>
                                <el-radio :label="9">服务体系人员</el-radio>
                            </el-radio-group>
                            <div class="lineBlock">
                                <p class="condition" v-if="personnelSources==6">供应商名称：</p>
                                <el-select size="mini" v-if="personnelSources==6" v-model="partnerPersonId"  @change="selectedPartnerList" placeholder="请选择">
                                    <el-option v-for="(partnerData,index) in partnerLists" :key="index" :label="partnerData.partnerName" :value="partnerData.id">
                                        <span style="float: left">{{ partnerData.partnerCode }}</span>
                                        <span style="float: right; color: #8492a6; font-size: 13px">{{ partnerData.partnerName }}</span>
                                    </el-option>
                                </el-select>
                            </div>
                            <div class="lineBlock bottom1">
                                <p class="condition" v-if="personnelSources==9">服务站名称：</p>
                                <el-select size="mini" v-if="personnelSources==9" v-model="serviceStationId"  @change="selectedServicePersonnelList" placeholder="请选择">
                                    <el-option v-for="(serviceStation,index) in serviceStationLists" :key="index" :label="serviceStation.stationCode":value="serviceStation.stationId">
                                        <span style="float: left">{{ serviceStation.stationCode }}</span>
                                        <span style="float: right; color: #8492a6; font-size: 13px">{{ serviceStation.stationName }}</span>
                                    </el-option>
                                </el-select>
                            </div>
                        </div>
                    </div>
                    <div class="left-transfer transfer-content">
                        <el-checkbox-group  v-model="dSpersonNoRole"  @change="handleLeftCheckedChange">
                            <el-checkbox v-for="leftPersonnel in personNoRoleList" :label="leftPersonnel.id" :key="leftPersonnel.personName">{{leftPersonnel.personName}}</el-checkbox>
                        </el-checkbox-group>
                    </div>
                </div>
                <!-- 操作按钮 -->
                <div class="center-transfer fleft">
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="toLeftTransfer"> << </el-button>
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="toRightTransfer"> >> </el-button>
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="clearCheckedValue"> 清除 </el-button>
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="submitResult"> 提交 </el-button>
                </div>
                <!-- 待选人员列表 -->
                <div class="right-box fright">
                    <div class="right-title">
                        <h2>库房库位人员列表</h2>
                        <el-form ref="rightForm" :inline="true" :model="rightForm" class="demo-form-inline">
                            <el-form-item label="库房名称" class="selectMB10 label-w2" prop="warehouseId"  :rules="[{ required: true, message: '库房名称不能为空'}]">
                                <el-select size="mini" v-model="rightForm.warehouseId"  @change="storageSectionDropDown" placeholder="请选择">
                                    <el-option v-for="(wareHouseMesg,index) in warehouseMesgLists" :key="index" :label="wareHouseMesg.name":value="wareHouseMesg.id">
                                        <span style="float: left">{{ wareHouseMesg.name }}</span>
                                        <span style="float: right; color: #8492a6; font-size: 13px">{{ wareHouseMesg.code }}</span>
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="库区名称" class="selectMB10 label-w2" prop="storageSectionId"  :rules="[{ required: true, message: '库区名称不能为空'}]">
                                <el-select size="mini" v-model="rightForm.storageSectionId" @change="selectedstorageSection"  placeholder="请选择"> 
                                    <el-option v-for="(storageSectionMesg,index) in storageSectionMesgLists" :key="index" :label="storageSectionMesg.name":value="storageSectionMesg.id">
                                        <span style="float: left">{{ storageSectionMesg.name }}</span>
                                        <span style="float: right; color: #8492a6; font-size: 13px">{{ storageSectionMesg.code }}</span>
                                    </el-option>
                                </el-select>
                            </el-form-item>                           
                        </el-form>
                    </div>
                    <div class="right-transfer transfer-content">
                        <el-checkbox-group v-model="dSpersonHasRole" @change="handleRightCheckedChange">
                            <el-checkbox v-for="personHasRole in personHasRoleList" :label="personHasRole.id" :key="personHasRole.personName">
                                {{personHasRole.personName}}
                            </el-checkbox>
                        </el-checkbox-group>
                    </div>
                </div>
            </div>
        </el-dialog>
        <!--导入弹框-->
        <el-dialog title="导入库位信息" id="importFile" :visible.sync="importFileVisible" size="tiny" :lock-scroll="false">
            <el-upload class="upload-demo"  :action="action" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList" :before-upload="beforeAvatarUpload" :on-success="handleAvatarSuccess">
                <el-button size="mini" type="danger">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传excel文件</div>
            </el-upload>
        </el-dialog>
    </div>
</template>
<script>
       export default {
        data() {
            return {
                // 查询表单
                whPAuthorityForm:{
                    userAccount:"",
                    userName:"",
                    partnerName:"",
                    legalPersonName:"",
                    warehouseCode:"",
                    warehouseName:"",
                    storageSectionCode:"",
                    storageSectionName:"",
                    status:""
                },
                whPAuthorityData:[],
                statusLists:[],   //当前状态下拉列表
                labelWidth:"100px",
                

                rightForm:{
                    warehouseId:"",  
                    warehouseCode:"",   //库房编码
                    warehouseName:"",   // 库房名称
                    storageSectionId:"",
                    storageSectionCode:"",   // 库区编码
                    storageSectionName:""   //库区名称

                },   // 右侧的form表单

                legalPersonId:"",     //法人id
                legalPersonName:"",   //法人名称
                legalPersonCode:"",   // 法人代码
                legalPersonLists:[],  // 法人列表

                partnerPersonId:"", 
                partnerPersonCode:"",   // 业务合作人员
                partnerPersonName:"",   // 业务合作人员
                providerCode:"",
                partnerLists:[],

                serviceStationId:"",
                servicePersonnelCode:"",
                serviceStationLists:[],
                personnelSources:"",     // 人员来源 3法人代码  6业务合作代码  9服务体系代码
                dSpersonHasRole:[],      // 右侧 当前角色下选中的人员
                personHasRoleList:[],    // 右侧 当前角色下的人员列表
                allPersonHasRoleList:[], // 所有拥有当前选中角色的用户
                allPersonUnderDept:[],   // 当前选中法人/服务站/供应商下面所有的用户
                dSpersonNoRole:[],       // 左侧 当前选项下选中的人员
                personNoRoleList:[],     // 左侧 当前选项下的人员列表





                warehouseMesgLists:[],   //新增弹窗库房信息
                storageSectionMesgLists:[],  // 新增弹窗库房库区信息
                addSureFlag:false,   // 新增的弹窗确定（不退出）

                loading:false,
                disabled:false,


                //弹窗
                dialogForm1Visible:false,
                dialogForm2Visible:false,
                // 分页
                isPaging:false,
                pageIndex:1,    //当前页（必传）
                pageSize :10,   //每页多少条
                totalNumber: 20,
                totalPage:2,
                
                //查询禁用
                selectDisabled:false,

                action:"",
                fileList: [],
                importFileVisible:false
            };
        },
       //进入页面立即运行此方法
       mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'WarehousePersonnelAuthority');
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });

            
            // 上传地址
            _this.action=_this.iwm_service+"userStorageLocationAccessaBility/import";


            _this.dropDownValue();// 当前状态下拉列表
            _this.queryWhPAuthority();    //表单查询
       },
        methods:{
            // 当前状态下来列表
            dropDownValue(){
                var _this=this;
                var tmp=["warehouse.warehouseRyqxStatus"];
                $.ajax({
                    type:'POST',
                    url:_this.iwm_service+'iwm/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:"application/json;charset=utf-8",
                    success:function(data){
                        if(data.success){
                            _this.statusLists=data.data['warehouse.warehouseRyqxStatus'];
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            //查询库房人员列表
            queryWhPAuthority(){
                var _this=this;
                _this.loading=true;
                var tmp={
                    userAccount:_this.whPAuthorityForm.userName,
                    userName:_this.whPAuthorityForm.userName,
                    partnerName:_this.whPAuthorityForm.partnerName,
                    legalPersonName:_this.whPAuthorityForm.legalPersonName,
                    warehouseCode:_this.whPAuthorityForm.warehouseCode,
                    warehouseName:_this.whPAuthorityForm.warehouseName,
                    storageSectionCode:_this.whPAuthorityForm.storageSectionCode,
                    storageSectionName:_this.whPAuthorityForm.storageSectionName,
                    status:_this.whPAuthorityForm.status,
                    pageIndex:_this.pageIndex,
                    pageSize:_this.pageSize
                };
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.iwm_service+"userStorageLocationAccessaBility/queryPage",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.loading=false;
                            _this.isPaging=true;
                            _this.totalPage=data.data.totalPage;
                            _this.totalNumber=data.data.totalNumber;
                            _this.whPAuthorityData=data.data.dataList;
                        }else{
                            _this.common.errorTip(data.errorMessage)
                        }
                        _this.selectDisabled=false;
                    }
                });
            },
            //导入按钮
            importFile(){
                var _this=this;
                _this.importFileVisible = true;
                _this.fileList=[];

            },
             //上传文件之前的钩子
            beforeAvatarUpload(file) {
                // console.log(file);
                const isExcel2007 = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                const isExcel2003 = file.type === 'application/vnd.ms-excel';
                if (!isExcel2007 && !isExcel2003) {
                    this.$message.error('只能上传excel文件!');
                }
                return isExcel2007 || isExcel2003 ;
            },
            // 文件上传成功时的钩子
             handleAvatarSuccess(res, file) {
                 var _this=this;
                if(res.success){
                    _this.common.successTip("上传成功！");
                    _this.importFileVisible = false;
                    //上传成功刷新页面
                    _this.queryWhPAuthority(_this.pageIndex,_this.pageSize);  
                }else{
                    _this.fileList=[];
                    _this.common.errorTip(res.errorMessage);
                }
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            //新增库房人员权限
            createNew(){
                var _this=this;
                _this.dialogForm1Visible=true; 
                if(this.$refs['addWhPAuthorityForm']) {
                    this.$refs['addWhPAuthorityForm'].resetFields();
                }

                _this.legalPersonId = ""; 
                _this.legalPersonName = ""; 
                _this.rightForm.warehouseId = ""; 
                _this.rightForm.warehouseCode = ""; 
                _this.rightForm.warehouseName = ""; 
                _this.rightForm.storageSectionId = "";
                _this.rightForm.storageSectionCode = "";  
                _this.rightForm.storageSectionName = "";  

                _this.personnelSources="";     // 人员来源 3法人代码  6业务合作代码  9服务体系代码
                _this.dSpersonHasRole=[];      // 右侧 当前角色下选中的人员
                _this.personHasRoleList=[];    // 右侧 当前角色下的人员列表
                _this.allPersonHasRoleList=[]; // 所有拥有当前选中角色的用户
                _this.allPersonUnderDept=[];   // 当前选中法人/服务站/供应商下面所有的用户
                _this.dSpersonNoRole=[];       // 左侧 当前选项下选中的人员
                _this.personNoRoleList=[];     // 左侧 当前选项下的人员列表

                _this.partnerPersonId = "";
                _this.partnerPersonCode = ""; 
                _this.partnerPersonName = "";

                _this.queryLegalPerson();  // 法人名称下拉列表
            },
            // 新增弹窗库房信息
            warehouseDropDown(){
                var _this=this;
                if(_this.legalPersonId){
                    $.ajax({
                        type:'GET',
                        url:_this.iwm_service+'warehouse/queryWarehouseList?legalPersonId='+_this.legalPersonId,
                        cache:false,
                        // data:JSON.stringify(tmp),
                        dataType:'JSON',
                        contentType:"application/json;charset=utf-8",
                        success:function(data){
                            if(data.success){
                                _this.warehouseMesgLists=data.data;
                            }else{
                                _this.common.errorTip(data.errorMessage);
                            }
                        }
                    })
                }else{
                    _this.common.errorTip("请选择法人！");
                }                
            },
            // 新增弹窗库区信息 
            storageSectionDropDown(){
                var _this=this;
                for(var item in _this.warehouseMesgLists){   // 根据选中的库房的ID取库房的编码及库房的名称
                    if(_this.rightForm.warehouseId == _this.warehouseMesgLists[item].id){
                        _this.rightForm.warehouseCode = _this.warehouseMesgLists[item].code;
                        _this.rightForm.warehouseName = _this.warehouseMesgLists[item].name;
                    }
                }
                if(_this.rightForm.warehouseId){   //  如果没有选择库房，则不能调取库区的下拉列表的接口
                    $.ajax({
                        type:'GET',
                        url:_this.iwm_service+'warehouse/queryStorageSectionByWarehouseIdAndLegalId?warehouseId='+_this.rightForm.warehouseId+'&legalPersonId='+_this.legalPersonId,
                        cache:false,
                        // data:JSON.stringify(tmp),
                        dataType:'JSON',
                        contentType:"application/json;charset=utf-8",
                        success:function(data){
                            if(data.success){
                                _this.storageSectionMesgLists=data.data;
                            }else{
                                _this.common.errorTip(data.errorMessage);
                            }
                        }
                    })
                }
                // else{
                    // _this.common.errorTip("请选择库房信息");
                // }                
            },
            // 根据选中的库区ID取code和name
            selectedstorageSection(){
                var _this=this;
                for(var item in _this.storageSectionMesgLists){
                    if(_this.rightForm.storageSectionId == _this.storageSectionMesgLists[item].id){
                        _this.rightForm.storageSectionCode = _this.storageSectionMesgLists[item].code;
                        _this.rightForm.storageSectionName = _this.storageSectionMesgLists[item].name;
                    }
                }
            },
            calculatePersonsHasRoleUnderDept(allPersonHasRole, personUnderDept){//有权限和无权限的用户应该显示那些
                var _this = this;
                var presonHasRoleIdArray = [];
                allPersonHasRole.forEach(function(personA){
                    personUnderDept.forEach(function(personB){
                        if(personA.id == personB.id){
                            presonHasRoleIdArray.push(personA.id);// 只要id
                        }
                    });
                });
                
                var presonHasRoleArray = [];
                var presonNoRoleArray = [];
                personUnderDept.forEach(function(personB){
                    if($.inArray(personB.id,presonHasRoleIdArray)>=0){   // 数组presonHasRoleIdArray里包含personB.id
                        presonHasRoleArray.push(personB);
                    }else {
                        presonNoRoleArray.push(personB);
                    }
                });

                _this._data.personHasRoleList = presonHasRoleArray;
                _this._data.personNoRoleList = presonNoRoleArray;
            },
            // 
            selectedWhMList(){
                var _this = this;

            },
            // 查询当前用户下的法人信息
            queryLegalPerson(){
                var _this = this;
                $.ajax({
                    type: 'GET',
                    url: _this.procurement_service + "legalPerson/ofCurrentUser",
                    cache: false,
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     
                    success: function (data) {
                        if (data.success) {
                            _this.legalPersonLists = data.data;        
                        } else {
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },
            // 选择人员来源
            handlePersonnelSources(){
                var _this=this;
                _this.personNoRoleList=[];
                // 供应商名称、供应商Id清空
                _this.partnerPersonId=null;
                // 服务站名称、服务站Id清空
                _this.serviceStationId=null;
                if(_this.personnelSources==3){
                    _this.selectedLegalPersonList(1);
                }else if(_this.personnelSources==6){
                    if(_this.legalPersonId){
                        _this.queryPartnerList();
                    }else{
                        _this.common.errorTip("请选择法人！");
                    }
                }else if(_this.personnelSources==9){
                    $.ajax({
                        type: 'POST',
                        url: _this.iwm_service+"userStorageLocationAccessaBility/listAllStation",
                        cache: false,
                        // data:JSON.stringify(tmp),
                        dataType:'JSON',
                        contentType: "application/json;charset=utf-8",
                        success: function (data) {
                            if (data.success) {
                                _this.serviceStationLists=data.data;    //服务体系人员列表
                            }else
                                _this.common.errorTip(data.errorMessage);
                        }
                    });
                }
            },
            //某个查询法人下的供应商列表接口
            queryPartnerList(){
                var _this = this;
                $.ajax({
                    type: 'GET',
                    url: _this.iwm_service + "userStorageLocationAccessaBility/queryByLegalPerson?legalPersonId="+_this.legalPersonId,
                    cache: false,
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     
                    success: function (data) {
                        if (data.success) {
                            _this.partnerLists = data.data;        // 业务合作人员列表
                        } else {
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },
            // change事件   选择法人名称 
            selectedLegalPersonList(pram){
                var _this=this;
                // 供应商名称、供应商Id清空
                _this.partnerPersonId=null;
                // 服务站名称、服务站Id清空
                _this.serviceStationId=null;
                // 左侧可选人员列表
                _this.personNoRoleList=[];
                if(pram != 1){
                    // 清空库房
                    _this.rightForm.warehouseId = null;
                    _this.warehouseMesgLists=[];
                    // 清空库区
                    _this.rightForm.storageSectionId = null;
                    _this.storageSectionMesgLists=[];
                    _this.warehouseDropDown();   // 选择了法人才能根据法人Id取库房信息下拉列表
                }                               

                if(_this.personnelSources != 9){  //如果可选人员选择的是服务体系人员，则选择法人与其无关
                    if(_this.legalPersonId){
                        for(var i in _this.legalPersonLists){
                            if(_this.legalPersonId == _this.legalPersonLists[i].id){
                                _this.legalPersonName = _this.legalPersonLists[i].legalPersonName;
                            }
                        }
                        _this.selectedLegalList(); // 先选择本部人员，然后选择法人名称，需要调取获取本部人员列表的接口
                        _this.queryPartnerList();   // 先选择业务合作人员，然后选择法人名称，需要调取获取业务合作人员列表的接口                      
                    }else{
                        _this.common.errorTip("请选择法人！");
                    }
                }      
            },
            // 本部人员  已选中人员下面的人员
            selectedLegalList(){
                var _this=this; 
                if(_this.legalPersonId){
                    if(_this.personnelSources == 3){
                        $.ajax({
                            type: 'GET',
                            url: _this.iwm_service + "userStorageLocationAccessaBility/queryUserListByLegalPersonId?legalPersonId="+_this.legalPersonId,
                            cache: false,
                            success: function (data) {
                                if (data.success) {
                                    _this.allPersonUnderDept=data.data;
                                    var clearList = _this.calculatePersonsHasRoleUnderDept(_this.allPersonHasRoleList, _this.allPersonUnderDept);
                                } else
                                    _this.common.errorTip(data.errorMessage);
                            }
                        });
                    }
                }else{
                    _this.common.errorTip("请选择法人！");
                }
            },
            // 业务合作人员  已选中人员下面的人员
            selectedPartnerList(){
                var _this=this; 
                for(var i=0;i<_this.partnerLists.length;i++){
                    if(_this.partnerPersonId == _this.partnerLists[i].id){
                        _this.partnerPersonCode = _this.partnerLists[i].code;
                        _this.partnerPersonName = _this.partnerLists[i].name;
                    }
                }
                if(_this.partnerPersonId){
                    $.ajax({
                        type: 'GET',
                        url: _this.iwm_service + "userStorageLocationAccessaBility/queryUserListByPartnerId?partnerPersonId="+_this.partnerPersonId,
                        cache: false,
                        success: function (data) {
                            if (data.success) {
                                // console.log("业务合作代码  已选中人员下面的人员");
                                // console.log(data.data);
                                _this.allPersonUnderDept=data.data;
                                var clearList = _this.calculatePersonsHasRoleUnderDept(_this.allPersonHasRoleList, _this.allPersonUnderDept);
                            } else
                                _this.common.errorTip(data.errorMessage);
                        }
                    });
                }
            },//

            // 服务体系代码  已选中人员下面的人员
            selectedServicePersonnelList(){
                var _this=this;
                if(_this.serviceStationId){
                    $.ajax({
                        type: 'GET',
                        url: _this.iwm_service + "userStorageLocationAccessaBility/queryUserListByStationId?stationId="+_this.serviceStationId,
                        data:{"stationId":_this.serviceStationId},
                        cache: false,
                        success: function (data) {
                            if (data.success) {
                                // console.log("服务体系代码  已选中人员下面的人员");
                                // console.log(data.data);
                                _this.allPersonUnderDept=data.data;
                                var clearList = _this.calculatePersonsHasRoleUnderDept(_this.allPersonHasRoleList, _this.allPersonUnderDept);
                            } else
                                _this.common.errorTip(data.errorMessage);
                        }
                    });
                }                
            },
            handleRightCheckedChange(){
                
            },
            handleLeftCheckedChange(){

            },
            // 向右
            toRightTransfer(){
                var _this=this;
                if(_this.dSpersonNoRole.length){
                    if(_this.rightForm.warehouseId){
                        if(_this.rightForm.storageSectionId){
                            var tempArray = [].concat(_this.dSpersonNoRole);
                            var personToMove = [];
                            var personLeft = [];
                            _this.personNoRoleList.forEach(function(personB){
                                if($.inArray(personB.id, tempArray) >= 0){
                                    personToMove.push(personB);
                                }else{
                                    personLeft.push(personB);
                                }
                            });
                            _this.dSpersonNoRole = [];
                            _this.personNoRoleList = personLeft;
                            _this.personHasRoleList = _this.personHasRoleList.concat(personToMove);
                        }else{
                        _this.common.errorTip("请选择库区名称");
                        }
                    }else{
                        _this.common.errorTip("请选择库房名称");
                    }                    
                }else{
                    _this.common.errorTip("暂无选中项");
                }

            },
            //向左
            toLeftTransfer(){
                var _this=this;
                if(_this.dSpersonHasRole.length){
                    var tempArray = [].concat(_this.dSpersonHasRole);
                    
                    // console.log(tempArray);
                    // console.log("tempArray.length=======" + tempArray.length);

                    var personToMove = [];
                    var personLeft = [];
                    _this.personHasRoleList.forEach(function(personB){
                        if($.inArray(personB.id, tempArray) >= 0){
                            personToMove.push(personB);
                        }else{
                            personLeft.push(personB);
                        }
                    });
                    _this.dSpersonHasRole = [];
                    _this.personHasRoleList = personLeft;
                    _this.personNoRoleList = _this.personNoRoleList.concat(personToMove);
                }else{
                    _this.common.errorTip("暂无选中项");
                }
            },
            //清除
            clearCheckedValue(){
                var _this=this;
                _this.personNoRoleList = _this.personNoRoleList.concat(_this.personHasRoleList);
                _this.dSpersonHasRole = [];
                _this.personHasRoleList = [];
            },
            //提交
            submitResult(){
                var _this=this;
                var tmpList = [],tmp={};
                if(_this.rightForm.warehouseId!=""){
                    if(_this.personnelSources==3){
                        if(_this.legalPersonId!=""){
                            for(var item in _this.personHasRoleList){
                                tmpList.push({
                                    "legalPersonId": _this.legalPersonId, 
                                    "legalPersonName": _this.legalPersonName, 

                                    "warehouseCode": _this.rightForm.warehouseCode,
                                    "warehouseName": _this.rightForm.warehouseName, 
                                    "storageSectionCode": _this.rightForm.storageSectionCode, 
                                    "storageSectionName": _this.rightForm.storageSectionName, 
                                    "userId": _this.personHasRoleList[item].id, 
                                    "userAccount": _this.personHasRoleList[item].userName,
                                    "userName": _this.personHasRoleList[item].personName
                                });
                            }
                            tmp={list:tmpList};
                            _this.submitRequest(tmp);//提交
                        }else{
                            _this.common.errorTip("请选择本部人员");
                        }
                    }else if(_this.personnelSources==6){
                        if(_this.partnerPersonId!=""){
                            for(var item in _this.personHasRoleList){
                                tmpList.push({
                                    "legalPersonId": _this.legalPersonId, 
                                    "legalPersonName": _this.legalPersonName,
                                    "partnerCode": _this.partnerPersonCode, 
                                    "partnerName": _this.partnerPersonName,

                                    "warehouseCode": _this.rightForm.warehouseCode,
                                    "warehouseName": _this.rightForm.warehouseName, 
                                    "storageSectionCode": _this.rightForm.storageSectionCode, 
                                    "storageSectionName": _this.rightForm.storageSectionName, 
                                    "userId": _this.personHasRoleList[item].id, 
                                    "userAccount": _this.personHasRoleList[item].userName,
                                    "userName": _this.personHasRoleList[item].personName
                                });
                            }
                            tmp={list:tmpList};
                            _this.submitRequest(tmp);//提交
                        }else{
                            _this.common.errorTip("请选择业务合作人员");
                        }
                    }else if(_this.personnelSources==9){
                        if(_this.serviceStationId!=""){
                            for(var item in _this.personHasRoleList){
                                tmpList.push({
                                    "warehouseCode": _this.rightForm.warehouseCode,
                                    "warehouseName": _this.rightForm.warehouseName, 
                                    "storageSectionCode": _this.rightForm.storageSectionCode, 
                                    "storageSectionName": _this.rightForm.storageSectionName, 
                                    "userId": _this.personHasRoleList[item].id, 
                                    "userAccount": _this.personHasRoleList[item].userName,
                                    "userName": _this.personHasRoleList[item].personName
                                });
                            }
                            tmp={list:tmpList};
                            _this.submitRequest(tmp);//提交
                        }else{
                            _this.common.errorTip("请选择服务体系人员");
                        }
                    }else{
                        _this.common.errorTip("请选择可选人员");
                    }
                }else{
                    _this.common.errorTip("请选择库房名称");
                }
            },
            //提交请求
            submitRequest(tmp){
                var _this=this;
                if(tmp.list.length){
                    $.ajax({
                        type: 'POST',
                        url: _this.iwm_service + "userStorageLocationAccessaBility/add",
                        cache: false,
                        data: JSON.stringify(tmp),
                        dataType: 'JSON',
                        contentType: "application/json;charset=utf-8",
                        success: function (data) {
                            if (data.success) {
                                _this.common.successTip("提交成功！");
                                _this.dialogForm1Visible = false;
                                _this.dSpersonNoRole=[];
                                _this.queryWhPAuthority();
                            } else
                                _this.common.errorTip(data.errorMessage);
                        }
                    });
                }else{
                    _this.common.errorTip("请选择人员！");
                }
                
            },
           
            // 操作启用禁用
            handleStatus(index, row){
                var _this=this;
                if(row.status){
                    row.status = false;
                }else{
                    row.status = true;
                }
                var tmp={id: row.id,status: row.status}; 
                $.ajax({
                    type: 'POST',
                    url: _this.iwm_service+"userStorageLocationAccessaBility/updateStatus",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            // 当前状态的显示
                            if(row.status){
                                row.statusName = "启用";
                                _this.common.successTip("启用成功！");
                            }else{
                                row.statusName = "禁用";
                                _this.common.successTip("禁用成功！");
                            }
                        }else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            //点击修改
            handleUpdate(index,row){
                var _this=this;
                // _this.dialogForm2Visible=true;
                // if(this.$refs['updateWhPositionForm']) {
                //     this.$refs['updateWhPositionForm'].resetFields();
                //  }
                // _this.updateWhPositionForm.id = row.id;
                // _this.updateWhPositionForm.name = row.name;
                // _this.updateWhPositionForm.code = row.code;
                // _this.updateWhPositionForm.storageSectionName = row.storageSectionName;
                // _this.updateWhPositionForm.storageSectionCode = row.storageSectionCode;
                // _this.updateWhPositionForm.storageSectionRemark = row.storageSectionRemark;
                // _this.updateWhPositionForm.wareHouseCode = row.wareHouseCode;
                // _this.updateWhPositionForm.wareHouseName = row.wareHouseName;
                // _this.updateWhPositionForm.wareHouseRemark = row.wareHouseRemark;
            },
            //修改保存
            handleUpdateSave(){
                var _this=this;
                // _this.$refs["updateWhPositionForm"].validate((valid) => {
                //     if (valid) {
                //         var tmp={
                //             id:_this.updateWhPositionForm.id,
                //             name:_this.updateWhPositionForm.name
                //             };
                //         $.ajax({
                //             type: 'POST',
                //             url: _this.iwm_service+"StorageBin/update",
                //             cache: false,
                //             data:JSON.stringify(tmp),
                //             dataType:'JSON',
                //             contentType: "application/json;charset=utf-8",
                //             success: function (data) {
                //                 if (data.success) {
                //                     _this.common.successTip("修改成功！");
                //                     _this.dialogForm2Visible=false;
                //                     _this.queryWhPAuthority();
                //                 }else
                //                     _this.common.errorTip(data.errorMessage);
                //             }
                //         });
                //     } else {
                //         _this.common.errorTip("存在未填写的必填项！");
                //         return false;
                //     }
                // });
            },
            //修改取消
            handleUpdateCancel(){
                var _this=this;
                // _this.dialogForm2Visible=false;
            },
            //   分页
            handleSizeChange(val) {
                var _this=this;
                _this.pageSize=val;
                _this.queryWhPAuthority();

            },
            //点击页码分页查询点击事件
            handleCurrentChange(val) {
                var _this=this;
                _this.pageIndex=val;
                _this.queryWhPAuthority();
            },
            // // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: '成功',
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: '错误',
            //         message: p
            //     });
            // }

        }
    }
</script>
